// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.


suite("test_cast_to_largeint_from_decimalv2_20_6") {

    // This test case is generated from the correspoinding be UT test case,
    // update this case if the correspoinding be UT test case is updated,
    // e.g.: ../run-be-ut.sh --run --filter=FunctionCastToDecimalTest.* --gen_regression_case
    sql "drop table if exists test_cast_to_largeint_from_decimalv2_20_6_0_nullable;"
    sql "create table test_cast_to_largeint_from_decimalv2_20_6_0_nullable(f1 int, f2 decimalv2(20, 6)) properties('replication_num'='1');"
    sql """insert into test_cast_to_largeint_from_decimalv2_20_6_0_nullable values (0, "0.000000"),(1, "0.000000"),(2, "0.000000"),(3, "0.000000"),(4, "0.000000"),(5, "0.000000"),(6, "0.001000"),(7, "-0.001000"),(8, "0.001000"),(9, "-0.001000"),(10, "0.000100"),(11, "-0.000100"),(12, "0.000900"),(13, "-0.000900"),(14, "0.000900"),(15, "-0.000900"),(16, "1.000000"),(17, "-1.000000"),(18, "1.000000"),(19, "-1.000000"),
      (20, "1.000000"),(21, "-1.000000"),(22, "1.001000"),(23, "-1.001000"),(24, "1.001000"),(25, "-1.001000"),(26, "1.000100"),(27, "-1.000100"),(28, "1.000900"),(29, "-1.000900"),(30, "1.000900"),(31, "-1.000900"),(32, "9.000000"),(33, "-9.000000"),(34, "9.000000"),(35, "-9.000000"),(36, "9.000000"),(37, "-9.000000"),(38, "9.001000"),(39, "-9.001000"),
      (40, "9.001000"),(41, "-9.001000"),(42, "9.000100"),(43, "-9.000100"),(44, "9.000900"),(45, "-9.000900"),(46, "9.000900"),(47, "-9.000900"),(48, "99999999999999.000000"),(49, "-99999999999999.000000"),(50, "99999999999999.000000"),(51, "-99999999999999.000000"),(52, "99999999999999.000000"),(53, "-99999999999999.000000"),(54, "99999999999999.001000"),(55, "-99999999999999.001000"),(56, "99999999999999.001000"),(57, "-99999999999999.001000"),(58, "99999999999999.000100"),(59, "-99999999999999.000100"),
      (60, "99999999999999.000900"),(61, "-99999999999999.000900"),(62, "99999999999999.000900"),(63, "-99999999999999.000900"),(64, "99999999999998.000000"),(65, "-99999999999998.000000"),(66, "99999999999998.000000"),(67, "-99999999999998.000000"),(68, "99999999999998.000000"),(69, "-99999999999998.000000"),(70, "99999999999998.001000"),(71, "-99999999999998.001000"),(72, "99999999999998.001000"),(73, "-99999999999998.001000"),(74, "99999999999998.000100"),(75, "-99999999999998.000100"),(76, "99999999999998.000900"),(77, "-99999999999998.000900"),(78, "99999999999998.000900"),(79, "-99999999999998.000900"),
      (80, "9999999999999.000000"),(81, "-9999999999999.000000"),(82, "9999999999999.000000"),(83, "-9999999999999.000000"),(84, "9999999999999.000000"),(85, "-9999999999999.000000"),(86, "9999999999999.001000"),(87, "-9999999999999.001000"),(88, "9999999999999.001000"),(89, "-9999999999999.001000"),(90, "9999999999999.000100"),(91, "-9999999999999.000100"),(92, "9999999999999.000900"),(93, "-9999999999999.000900"),(94, "9999999999999.000900"),(95, "-9999999999999.000900"),(96, "90000000000000.000000"),(97, "-90000000000000.000000"),(98, "90000000000000.000000"),(99, "-90000000000000.000000"),
      (100, "90000000000000.000000"),(101, "-90000000000000.000000"),(102, "90000000000000.001000"),(103, "-90000000000000.001000"),(104, "90000000000000.001000"),(105, "-90000000000000.001000"),(106, "90000000000000.000100"),(107, "-90000000000000.000100"),(108, "90000000000000.000900"),(109, "-90000000000000.000900"),(110, "90000000000000.000900"),(111, "-90000000000000.000900"),(112, "90000000000001.000000"),(113, "-90000000000001.000000"),(114, "90000000000001.000000"),(115, "-90000000000001.000000"),(116, "90000000000001.000000"),(117, "-90000000000001.000000"),(118, "90000000000001.001000"),(119, "-90000000000001.001000"),
      (120, "90000000000001.001000"),(121, "-90000000000001.001000"),(122, "90000000000001.000100"),(123, "-90000000000001.000100"),(124, "90000000000001.000900"),(125, "-90000000000001.000900"),(126, "90000000000001.000900"),(127, "-90000000000001.000900")
      ,(128, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_0_strict 'select f1, cast(f2 as largeint) from test_cast_to_largeint_from_decimalv2_20_6_0_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_0_non_strict 'select f1, cast(f2 as largeint) from test_cast_to_largeint_from_decimalv2_20_6_0_nullable order by 1;'

    sql "drop table if exists test_cast_to_largeint_from_decimalv2_20_6_0_not_nullable;"
    sql "create table test_cast_to_largeint_from_decimalv2_20_6_0_not_nullable(f1 int, f2 decimalv2(20, 6)) properties('replication_num'='1');"
    sql """insert into test_cast_to_largeint_from_decimalv2_20_6_0_not_nullable values (0, "0.000000"),(1, "0.000000"),(2, "0.000000"),(3, "0.000000"),(4, "0.000000"),(5, "0.000000"),(6, "0.001000"),(7, "-0.001000"),(8, "0.001000"),(9, "-0.001000"),(10, "0.000100"),(11, "-0.000100"),(12, "0.000900"),(13, "-0.000900"),(14, "0.000900"),(15, "-0.000900"),(16, "1.000000"),(17, "-1.000000"),(18, "1.000000"),(19, "-1.000000"),
      (20, "1.000000"),(21, "-1.000000"),(22, "1.001000"),(23, "-1.001000"),(24, "1.001000"),(25, "-1.001000"),(26, "1.000100"),(27, "-1.000100"),(28, "1.000900"),(29, "-1.000900"),(30, "1.000900"),(31, "-1.000900"),(32, "9.000000"),(33, "-9.000000"),(34, "9.000000"),(35, "-9.000000"),(36, "9.000000"),(37, "-9.000000"),(38, "9.001000"),(39, "-9.001000"),
      (40, "9.001000"),(41, "-9.001000"),(42, "9.000100"),(43, "-9.000100"),(44, "9.000900"),(45, "-9.000900"),(46, "9.000900"),(47, "-9.000900"),(48, "99999999999999.000000"),(49, "-99999999999999.000000"),(50, "99999999999999.000000"),(51, "-99999999999999.000000"),(52, "99999999999999.000000"),(53, "-99999999999999.000000"),(54, "99999999999999.001000"),(55, "-99999999999999.001000"),(56, "99999999999999.001000"),(57, "-99999999999999.001000"),(58, "99999999999999.000100"),(59, "-99999999999999.000100"),
      (60, "99999999999999.000900"),(61, "-99999999999999.000900"),(62, "99999999999999.000900"),(63, "-99999999999999.000900"),(64, "99999999999998.000000"),(65, "-99999999999998.000000"),(66, "99999999999998.000000"),(67, "-99999999999998.000000"),(68, "99999999999998.000000"),(69, "-99999999999998.000000"),(70, "99999999999998.001000"),(71, "-99999999999998.001000"),(72, "99999999999998.001000"),(73, "-99999999999998.001000"),(74, "99999999999998.000100"),(75, "-99999999999998.000100"),(76, "99999999999998.000900"),(77, "-99999999999998.000900"),(78, "99999999999998.000900"),(79, "-99999999999998.000900"),
      (80, "9999999999999.000000"),(81, "-9999999999999.000000"),(82, "9999999999999.000000"),(83, "-9999999999999.000000"),(84, "9999999999999.000000"),(85, "-9999999999999.000000"),(86, "9999999999999.001000"),(87, "-9999999999999.001000"),(88, "9999999999999.001000"),(89, "-9999999999999.001000"),(90, "9999999999999.000100"),(91, "-9999999999999.000100"),(92, "9999999999999.000900"),(93, "-9999999999999.000900"),(94, "9999999999999.000900"),(95, "-9999999999999.000900"),(96, "90000000000000.000000"),(97, "-90000000000000.000000"),(98, "90000000000000.000000"),(99, "-90000000000000.000000"),
      (100, "90000000000000.000000"),(101, "-90000000000000.000000"),(102, "90000000000000.001000"),(103, "-90000000000000.001000"),(104, "90000000000000.001000"),(105, "-90000000000000.001000"),(106, "90000000000000.000100"),(107, "-90000000000000.000100"),(108, "90000000000000.000900"),(109, "-90000000000000.000900"),(110, "90000000000000.000900"),(111, "-90000000000000.000900"),(112, "90000000000001.000000"),(113, "-90000000000001.000000"),(114, "90000000000001.000000"),(115, "-90000000000001.000000"),(116, "90000000000001.000000"),(117, "-90000000000001.000000"),(118, "90000000000001.001000"),(119, "-90000000000001.001000"),
      (120, "90000000000001.001000"),(121, "-90000000000001.001000"),(122, "90000000000001.000100"),(123, "-90000000000001.000100"),(124, "90000000000001.000900"),(125, "-90000000000001.000900"),(126, "90000000000001.000900"),(127, "-90000000000001.000900");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_0_strict 'select f1, cast(f2 as largeint) from test_cast_to_largeint_from_decimalv2_20_6_0_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_0_non_strict 'select f1, cast(f2 as largeint) from test_cast_to_largeint_from_decimalv2_20_6_0_not_nullable order by 1;'

}